package com.atguigu.listen;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class Mylisten {

    //默认采用自动确认消息。消费者获取消息处理后，自动给服务器发送异步确认。服务器收到确认就会删除队列的消息。
    @RabbitListener(queues = "atguigu.queue.simple") //监听指定名称队列。
    public void messageHandler(String msg, Message message, Channel channel){
        System.out.println("msg = " + msg);

        byte[] body = message.getBody(); //消息体,消息字符串对应的二进制属性。
        String str = new String(body);
        System.out.println("str = " + str);

        MessageProperties messageProperties = message.getMessageProperties();  //消息属性信息：例如，长度，字符编码，内容类型，优先级等
        System.out.println("messageProperties = " + messageProperties);
    }
    @RabbitListener(queues = "atguigu.queue.work")
    public void messworkhandler(String msg, Message message, Channel channel){
        System.out.println("work1msg = " + msg);
    }
    @RabbitListener(queues = "atguigu.queue.work")
    public void messworkhandler2(String msg, Message message, Channel channel){
        System.out.println("work2msg = " + msg);
    }
    @RabbitListener(queues = {"atguigu.queue.fanout01"})
    public void processMessage01(String messageContent, Message message, Channel channel) {
        System.out.println("Consumer01 Message Content:" + messageContent);
    }

    @RabbitListener(queues = {"atguigu.queue.fanout02"})
    public void processMessage02(String messageContent, Message message, Channel channel) {
        System.out.println("Consumer02 Message Content:" + messageContent);
    }
    @RabbitListener(queues = {"atguigu.queue.direct"})
    public void processMessageRouting(String messageContent, Message message, Channel channel) {
        System.out.println("Message Content:" + messageContent);
    }
    @RabbitListener(queues = {"atguigu.queue.message"})
    public void processMessage5(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Message:" + messageContent);
    }

    @RabbitListener(queues = {"atguigu.queue.order"})
    public void processMessage6(String messageContent, Message message, Channel channel) {
        System.out.println("Queue Order:" + messageContent);
    }

}
